package com.jameci.luntan.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PaginationDTO {
    private List<PostDTO> postDTOs;
    private Boolean showFirstPage;
    private Boolean showLastPage;
    private Boolean showNext;
    private Boolean showPrevious;
    private Integer page;
    private Integer size;
    private int lastPage;
    private List<Integer> pages;

    public void setPaginationDTO(Integer totalCount, int page, int size) {
        pages  = new ArrayList<>();
        int totalPage = (totalCount + size - 1) / size;
        setLastPage(totalPage);
        setShowPrevious(page != 1);
        setShowNext(page != totalPage);
        setShowFirstPage(page > 4);
        setShowLastPage(page < totalPage - 3);
        for(int i = Math.max(page - 4, 1); i <= Math.min(page + 3, totalPage); ++i) {
            pages.add(i);
        }
        this.page = page;
    }
}
